//
//  FBDDownloadManger.m
//  AVPlayerTest
//
//  Created by feng on 16/9/20.
//  Copyright © 2016年 冯宝东. All rights reserved.
//

#import "FBDDownloadManger.h"
#import "FBDDownload.h"
static FBDDownloadManger *sigleTan;

@implementation FBDDownloadManger

{

    NSURLSession * _currentSession;
}
-(NSMutableArray*)allDownURL
{
    if (!_allFBDDownObj) {
        _allFBDDownObj=[NSMutableArray array];
    }
    return _allFBDDownObj;
}
+(instancetype)defaultTool
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sigleTan=[[self alloc]init];
        
    });
    return sigleTan;
}
//设置当前的进度回调
-(void)configeAllCurrentDownloadBlock:(downloadCurrentBlock)downBlock
{
    self.currentDownBlock=downBlock;

    
}

//设置当前的进度回调
-(void)fbdDownloadMangerConfigeAllCurrentDownloadBlock:(downloadCurrentBlock)downBlock
{
    self.currentDownBlock=downBlock;


}
//设置当前的完成回调
-(void)fbdDownloadMangerConfigeDownloadCompleteBlock:(downloadCompleteBlock)completeBlock
{
    self.completeBlock=completeBlock;
}

//开始下载目标的URL数组
-(void)beginDownLoadMArrayURL:(NSMutableArray*)urlMarray
{
    for (NSString*URLStr in urlMarray) {
    FBDDownload * downloadObj =[[FBDDownload alloc]initWithDownLoadURL:URLStr];
    [self.allFBDDownObj addObject:downloadObj];
    [downloadObj fbdDownloadConfigeCurrentDownloadBlock:^(NSString *url, float progress) {
            if (_currentDownBlock)
            {
                 _currentDownBlock(url,progress);
            }
        }];
        
    [downloadObj fbdDownloadConfigeCompleteDownloadBlock:^(NSString *url, BOOL isDone, NSString *filePath) {
        if (_completeBlock) {
            _completeBlock(url,isDone,filePath);
        }
        
        }];
        
    }
}

//暂停当前所有的URL下载
-(void)cacelAllLoadingMArrayURL
{
   
    for (FBDDownload*currentDown in self.allDownURL)
    {
        [currentDown cancelIndexDownLoad];
    }
    
    
    
}


@end
